#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using lvec1 = vector<long long>;
using ivec1 = vector<int>;
using lvec2 = vector<vector<long long>>;
using ivec2 = vector<vector<int>>;

void dfs(ivec2 &gh, lvec1 &size, lvec1 &dp, int u, int p)
{
        for(auto v : gh[u]){
                if(v != p){
                        dfs(gh, size, dp, v, u);
                        size[u] += size[v];
                        dp[u] += dp[v];
                }
        }
        dp[u] += size[u];
}

void dfs2(ivec2 &gh, lvec1 &size, lvec1 &dp, int u, int p, int n)
{
        for(auto v : gh[u]){
                if(v != p){
                        dp[v] = dp[u] + n - size[v] - size[v];
                        dfs2(gh, size, dp, v, u, n);
                }
        }
}



int main()
{
	int n = 0;
	cin >> n;

	ivec2 gh(n + 1);
	for (int i = 0, u, v; i < n - 1; i++) {
                cin >> u >> v;
                gh[u].push_back(v);
                gh[v].push_back(u);
	}

        lvec1 size(n + 1, 1), dp(n + 1, 0);
        dfs(gh, size, dp, 1, 0);
        dfs2(gh, size, dp, 1, 0, n);
        cout << *max_element(dp.begin(), dp.end()) << endl;
        return 0;
}
